#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QTimer>
#include <QShortcut>
#include <memory>
#include <list>
#include <random>
#include "square.h"
#include "pathfinding.h"

namespace Ui {
class Widget;
}

class Widget : public QWidget
{
    Q_OBJECT

  public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();
  private slots:
    void on_btnReset_clicked();

    void on_btnStart_clicked();

    void onTimeOut();

  private:
    Ui::Widget *ui;
    bool once;
    const int kSize;
    PathFinding aStar;
    std::unique_ptr<QTimer> timer;
    std::unique_ptr<QShortcut> kQuit;
    std::unique_ptr<QShortcut> kReset;
    std::unique_ptr<QShortcut> kStart;
    std::list<Square*> world;
    std::list<Square*> blocks;
    Square* target;
    Square* start;
    std::random_device rd;
    std::list<Point*> closeSet;
    std::list<Point> path;

    void init();

    int genRand(size_t n);

    void setUpStartandTarget(Square::Id id);

    Square* findPos(const Point& pos);
};

#endif // WIDGET_H
